import java.util.*;

/**
 * The Straight class models a hand of straight
 * @author Xu Chen
 */
public class Straight extends Hand{
	/**
	 * a constructor for building a hand with the specified player and list of cards.
	 * @param player is the player playing this hand
	 * @param cards is the cards in this hand
	*/
	public Straight(CardGamePlayer player, CardList cards) {
		super(player, cards);
	}
	/**
	*
	*a method for retrieving the top card of this hand.
	*@return the top card of this hand
	*/
	public Card getTopCard() {
		this.sort();
		if (this.getCard(1).rank==1) {
			return this.getCard(1);
		}else if (this.getCard(0).rank==0) {
			return this.getCard(0);
		}else if (this.getCard(0).rank>=2){
			return this.getCard(4);
		}
		return this.getCard(4);
	}
	/**
	*
	*a method for checking if this is a valid hand.
	*@return true if this hand is valid
	*/
	public boolean isValid() {
		ArrayList<Integer> listOfRank = new ArrayList<Integer>();
//		Integer num = listOfNumbers.get(0);
//		int intNum = num.intValue();
		if(this.size()==5) {
		for (int i=0;i<5;i++) {
			if (this.getCard(i).getRank()==0) {
				listOfRank.add(new Integer(13));
				continue;
			}
			if (this.getCard(i).getRank()==1) {
				listOfRank.add(new Integer(14));
				continue;
			}
			listOfRank.add(new Integer(this.getCard(i).getRank()));
		}}
		
		Collections.sort(listOfRank);
		if(this.size()==5) {
			for (int j=0;j<4;j++){
				if(listOfRank.get(j+1)-listOfRank.get(j)==1) {
					continue;
				}else {
					return false;
				}
			}
			return true;
		}
		return false;
	};
	/**
	*
	* a method for returning a string specifying the type of this hand
	*@return "Straight"
	*/
	public String getType() {
		return "Straight";
	};
}